package com.appstore.controller;

import com.appstore.common.AjaxResult;
import com.appstore.common.utils.SecurityUtils;
import com.appstore.domain.entity.DownloadHistory;
import com.appstore.service.DownloadHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@Slf4j
@RestController
@RequestMapping("/download_history")
public class DownloadHistoryController {

    @Resource
    private DownloadHistoryService downloadHistoryService;

    @GetMapping("/userId")
    public AjaxResult getDownloadHistoryByUserId() {
        String userId = String.valueOf(SecurityUtils.getUserId());
        log.info("userid is {}", userId);
        return AjaxResult.success("查询下载历史成功！",downloadHistoryService.getDownloadHistoryByUserId(userId));
    }

    @PostMapping
    public AjaxResult addDownloadHistory(@RequestBody DownloadHistory downloadHistory) {
        return AjaxResult.success(downloadHistoryService.addDownloadHistory(downloadHistory));
    }
}
